<!DOCTYPE html>
<html>

<head>
    <title>WebSocket Example</title>
    <script src="https://cdn.jsdelivr.net/npm/sockjs-client/dist/sockjs.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/stompjs/lib/stomp.min.js"></script>
</head>

<body>
    <div id="messages"></div>
    <script>
        var socket = new SockJS('http://192.168.1.4:8081/ws');
        var stompClient = Stomp.over(socket);

        stompClient.connect({}, function (frame) {
            console.log('Connected: ' + frame);
            stompClient.subscribe('/topic/messages', function (message) {
                var messages = document.getElementById('messages');
                var messageElement = document.createElement('div');
                messageElement.textContent = message.body;
                messages.appendChild(messageElement);
            });
        });

        function sendMessage() {
            var message = document.getElementById('message').value;
            stompClient.send("/app/sendMessage", {}, message);
        }
    </script>
    <input type="text" id="message" placeholder="Enter message">
    <button onclick="sendMessage()">Send</button>
</body>

</html>